package edu.pxxy.yzj.adapt;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import java.util.List;

import edu.pxxy.yzj.R;
import edu.pxxy.yzj.domain.Food;

public class MenuAdapt extends ArrayAdapter<Food> {
    private final int resourceId;
    public MenuAdapt(@NonNull Context context, int resource, List<Food> foodList) {
        super(context, resource,foodList);
        this.resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Food food= getItem(position);//获取当前food的实例
        //View view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);
        TextView foodName=view.findViewById(R.id.foodName);
        TextView foodPrice=view.findViewById(R.id.foodPrice);
        TextView count=view.findViewById(R.id.foodCount);
        foodName.setText(food.getFoodname());
        foodPrice.setText(food.getFoodprice().toString());
        count.setText(String.valueOf(food.getCount()));
        return view;
       /* Fruit fruit = (Fruit) getItem(position); // 获取当前项的Fruit实例
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);//实例化一个对象
        ImageView fruitImage = (ImageView) view.findViewById(R.id.fruit_image);//获取该布局内的图片视图
        TextView fruitName = (TextView) view.findViewById(R.id.fruit_name);//获取该布局内的文本视图
        fruitImage.setImageResource(fruit.getImageId());//为图片视图设置图片资源
        fruitName.setText(fruit.getName());//为文本视图设置文本内容
        return view;*/
    }
}
